#pragma once

namespace Xide
{
	template <class T>
	struct List_ndoe
	{
		List_node<T>* _next;
		List_ndoe<T>* _prev;
		T _data;

		List_ndoe(const T& x)
			:_next(nullptr)
			, _prev(nullptr)
			, _data(x)
		{}
	};
	template<class T>
	struct List_iterrator
	{
		typedef List_node node;
		node* _pnode;

		List_iterrator(node* p)
			:_pnode(p)
		{}
		T& operator*()
		{
			return _pnode->data;
		}
		List_iterrator<T>& operator++()
		{
			_pnode = _pnode->next;
			return *this;
		}
		bool operator!=(const __list_iterator<T>& it)
		{
			return _pnode != it._pnode;
		}
	};

	template <class T>
	class List
	{
		typedef List_node node;
	public:
		typedef __list_iterator<T> iterator;
		iterator begin()
		{
			return iterator(_head->_next);
		}

		iterator end()
		{
			return iterator(_head);
		}
		List()
		{
			_head = new node(T());
			_head->_next = _head;
			_head->_prev = _head;
		}

		void push_back(const T& x)
		{
			node* newnode = new node(x);
			node* tail = _head->_prev;
			tail->_next = newnode;
			newnode->_prev = tail;
			newnode->_next = _head;
			_head->_prev = newnode;
		}
	private:
		node* _head;
	};
}
